package gl.live.danceshow.ui.camera;

import gl.live.mediamux.utils.FileUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.Log;

public class InitApplication extends Application {
	private double density;

	public static int mNetWorkState;

	private static final String FORMAT = "^[a-z,A-Z].*$";

	public static String WAV_HEADER = null;// this header MUST be created.

	@Override
	public void onCreate() {
		super.onCreate();
		initWavHeader();
	}

	private void initWavHeader() {
		WAV_HEADER = getFilesDir() + "/wav_header.wav";

		File header = new File(WAV_HEADER);
		if (header.exists())
			return;

		try {

			header.createNewFile();

			int samplerate = 44100;
			int channels = 2;
			int bitrate = (16 * samplerate * channels) / 8;

			FileOutputStream out = new FileOutputStream(header);
			int size = 30;
			FileUtil.WriteWaveFileHeader(out, size, size + 36, samplerate,
					channels, bitrate);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void getAssetData(Context act) {
		try {
			PackageManager manager = act.getPackageManager();
			PackageInfo info = manager.getPackageInfo(act.getPackageName(), 0);

			DisplayMetrics dm = new DisplayMetrics();
			dm = act.getResources().getDisplayMetrics();
			setDensity(dm.density); //
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
	}

	public double getDensity() {
		return density;
	}

	public void setDensity(double density) {
		this.density = density;
	}
}
